package com.torlesse.elasticsearch.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: torlesse-liang
 * @Date: 2022/02/24/21:55
 * @Description: ElasticSearchConfig RestHighLevelClient
 */
@Configuration
public class ElasticSearchConfig {

    @Value("${torlesse.es.hostname}")
    private String hostname;

    @Value("${torlesse.es.port}")
    private Integer port;

    @Value("${torlesse.es.scheme}")
    private String scheme;

    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                new HttpHost(hostname,port,scheme))
        );
        return client;
    }
}
